package com.alexsun.loginview

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast

class MainActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val button: Button = findViewById(R.id.button)
        button.setOnClickListener(this)
    }

    override fun onClick(p0: View?) {
        val username = findViewById<EditText>(R.id.editTextTextPersonName).text.toString()
        val password = findViewById<EditText>(R.id.editTextTextPassword).text.toString()
        if (username == "czu" && password == "123") {
            val intent = Intent()
            intent.putExtra("username", username)
            intent.setClass(this, HelloActivity::class.java)
            startActivity(intent)
        } else {
            Toast.makeText(this@MainActivity, "用户名或密码错误！", Toast.LENGTH_SHORT).show()
        }
    }
}